home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Graphics / sKulpt / skulpt-src / D3dmath.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-08  |  3.7 KB  |  83 lines

  1. //-----------------------------------------------------------------------------
  2. // File: D3DMath.h
  3. //
  4. // Desc: Math functions and shortcuts for Direct3D programming.
  5. //
  6. // Copyright (c) 1997-1999 Microsoft Corporation. All rights reserved
  7. //-----------------------------------------------------------------------------
  8. #ifndef D3DMATH_H
  9. #define D3DMATH_H
  10. #include <ddraw.h>
  11. #include <d3d.h>
  12.  
  13.  
  14. //-----------------------------------------------------------------------------
  15. // Useful Math constants
  16. //-----------------------------------------------------------------------------
  17. const FLOAT g_PI       =  3.14159265358979323846f; // Pi
  18. const FLOAT g_2_PI     =  6.28318530717958623200f; // 2 * Pi
  19. const FLOAT g_PI_DIV_2 =  1.57079632679489655800f; // Pi / 2
  20. const FLOAT g_PI_DIV_4 =  0.78539816339744827900f; // Pi / 4
  21. const FLOAT g_INV_PI   =  0.31830988618379069122f; // 1 / Pi
  22. const FLOAT g_DEGTORAD =  0.01745329251994329547f; // Degrees to Radians
  23. const FLOAT g_RADTODEG = 57.29577951308232286465f; // Radians to Degrees
  24. const FLOAT g_HUGE     =  1.0e+38f;                // Huge number for FLOAT
  25. const FLOAT g_EPSILON  =  1.0e-5f;                 // Tolerance for FLOATs
  26.  
  27.  
  28.  
  29.  
  30. //-----------------------------------------------------------------------------
  31. // Fuzzy compares (within tolerance)
  32. //-----------------------------------------------------------------------------
  33. inline BOOL D3DMath_IsZero( FLOAT a, FLOAT fTol = g_EPSILON )
  34. { return ( a <= 0.0f ) ? ( a >= -fTol ) : ( a <= fTol ); }
  35.  
  36.  
  37.  
  38.  
  39. //-----------------------------------------------------------------------------
  40. // Matrix functions
  41. //-----------------------------------------------------------------------------
  42. VOID    D3DMath_MatrixMultiply( D3DMATRIX& q, D3DMATRIX& a, D3DMATRIX& b );
  43. HRESULT D3DMath_MatrixInvert( D3DMATRIX& q, D3DMATRIX& a );
  44.  
  45. HRESULT D3DMath_MatrixTranspose( D3DMATRIX& q, D3DMATRIX& a );
  46.  
  47.  
  48.  
  49. //-----------------------------------------------------------------------------
  50. // Vector functions
  51. //-----------------------------------------------------------------------------
  52. HRESULT D3DMath_VectorMatrixMultiply( D3DVECTOR& vDest, D3DVECTOR& vSrc,
  53.                                       D3DMATRIX& mat);
  54. HRESULT D3DMath_VertexMatrixMultiply( D3DVERTEX& vDest, D3DVERTEX& vSrc,
  55.                                       D3DMATRIX& mat );
  56.  
  57.  
  58.  
  59.  
  60. //-----------------------------------------------------------------------------
  61. // Quaternion functions
  62. //-----------------------------------------------------------------------------
  63. VOID D3DMath_QuaternionFromRotation( FLOAT& x, FLOAT& y, FLOAT& z, FLOAT& w,
  64.                                      D3DVECTOR& v, FLOAT fTheta );
  65. VOID D3DMath_RotationFromQuaternion( D3DVECTOR& v, FLOAT& fTheta,
  66.                                      FLOAT x, FLOAT y, FLOAT z, FLOAT w );
  67. VOID D3DMath_QuaternionFromAngles( FLOAT& x, FLOAT& y, FLOAT& z, FLOAT& w,
  68.                                    FLOAT fYaw, FLOAT fPitch, FLOAT fRoll );
  69. VOID D3DMath_MatrixFromQuaternion( D3DMATRIX& mat, FLOAT x, FLOAT y, FLOAT z,
  70.                                    FLOAT w );
  71. VOID D3DMath_QuaternionFromMatrix( FLOAT &x, FLOAT &y, FLOAT &z, FLOAT &w,
  72.                                    D3DMATRIX& mat );
  73. VOID D3DMath_QuaternionMultiply( FLOAT& Qx, FLOAT& Qy, FLOAT& Qz, FLOAT& Qw,
  74.                                  FLOAT Ax, FLOAT Ay, FLOAT Az, FLOAT Aw,
  75.                                  FLOAT Bx, FLOAT By, FLOAT Bz, FLOAT Bw );
  76. VOID D3DMath_QuaternionSlerp( FLOAT& Qx, FLOAT& Qy, FLOAT& Qz, FLOAT& Qw,
  77.                               FLOAT Ax, FLOAT Ay, FLOAT Az, FLOAT Aw,
  78.                               FLOAT Bx, FLOAT By, FLOAT Bz, FLOAT Bw,
  79.                               FLOAT fAlpha );
  80.  
  81.  
  82. #endif // D3DMATH_H
  83.